package com.ssm.service.impl;

import com.ssm.dao.LogDao;
import com.ssm.dao.UserDao;
import com.ssm.entity.Log;
import com.ssm.entity.User;
import com.ssm.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by bai on 2017/8/1.
 */
@Service("logService")
public class LogServiceImpl implements LogService{

    /*日志管理业务层接口实现类*/
    @Autowired(required = false)
    private LogDao logDao;
    private UserDao userDao;


    //显示数据库中的所有日志(日志管理页面)
    public List<Log> queryAll() {

        return logDao.queryAll();
    }


    //根据用户名查看其名下的所有日志记录
    public List<Log> queryByUserName(String userName) {

        User user = userDao.queryByName(userName);

        return logDao.queryByUserId(user.getId());
    }


    //（系统）添加一条日志
    public Log addLog(Log log) {

        logDao.addLog(log.getUserId(),log.getOperations(),log.getTime());
        return log;
    }


    //删除特定用户的日志
    public void deleteLogByUserId(int userId) {

        logDao.deleteLogByUserId(userId);

    }
    //清空所有日志
    public void deleteAll(){

        logDao.deleteAll();
    }


}
